<template>
  <div
    class="top"
    style="overflow-y: hidden"
    v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <div class="flex">
      <div class="flexchder">
        <el-button :type="allsexall" @click="timbrelist">全部</el-button>
      </div>
      <div class="flexchder">
        <el-button :type="allsex1s" @click="allsex1">男声</el-button>
      </div>
      <div class="flexchder">
        <el-button :type="allsex2s" @click="allsex2">女声</el-button>
      </div>
    </div>
    <div class="buttonclienttext"><span>点击选择音色</span></div>
    <el-scrollbar style="height: 100%" wrap-style="overflow-x:hidden;">
      <div class="loopBody">
        <div
          v-for="item in list"
          :key="item.id"
          :class="showid === item.id ? 'clickBody' : 'body'"
        >
          <div @click="timbers(item, item.id)">
            <div v-if="item.sex === 1">
              <div class="sexs">
                <img src="@/assets/Snipaste_2022-11-22_15-30-29.png" />
              </div>
              <div class="texts">
                <span>磁性男声</span><br />
                <span> {{ item.show_name }}</span>
              </div>
            </div>
            <div v-else>
              <div class="sexs">
                <img src="@/assets/03b0d39583f48206768a7534e55bcpng.png" />
              </div>
              <div class="texts">
                <span>性感女声</span><br />
                <span> {{ item.show_name }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-scrollbar>
  </div>
</template>

<script>
import { virtuatimbrellist } from "@/api/virtualhuman";
export default {
  name: "Timbre",
  data() {
    return {
      allsexall: "primary",
      allsex1s: "info",
      allsex2s: "info",
      list: [],
      showid: null,
      loading: false,
    };
  },
  mounted() {
    this.timbrelist();
  },
  methods: {
    virtuatimbrellists(sex) {
      this.loading = true;
      virtuatimbrellist({ pageIndex: 1, pageSize: 50, sex }).then((res) => {
        if (res.code === 200) {
          this.list = res.data.list;
          this.allsexall = "primary";
          this.allsex1s = "info";
          this.allsex2s = "info";
          this.loading = false;
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
          this.loading = false;
        }
      });
    },
    //获取全部声音
    timbrelist() {
      this.virtuatimbrellists();
    },
    timbers(val, id) {
      this.$emit("timbersingle", val, id);
      this.showid = id;
    },
    //获取男生
    allsex1() {
      this.loading = true;
      virtuatimbrellist({ pageIndex: 1, pageSize: 50, sex: 1 }).then((res) => {
        if (res.code === 200) {
          this.list = res.data.list;
          this.allsexall = "info";
          this.allsex1s = "primary";
          this.allsex2s = "info";
          this.loading = false;
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
          this.loading = false;
        }
      });
    },
    //获取女声
    allsex2() {
      this.loading = true;
      virtuatimbrellist({ pageIndex: 1, pageSize: 50, sex: 2 }).then((res) => {
        if (res.code === 200) {
          this.list = res.data.list;
          this.allsexall = "info";
          this.allsex1s = "info";
          this.allsex2s = "primary";
          this.loading = false;
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
          this.loading = false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.flex {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .flexchder {
    width: 32%;
    & > .el-button {
      margin: 0;
      width: 100%;
    }
  }
}
.buttonclienttext {
  color: rgb(168, 168, 168);
  margin-top: 10px;
  font-size: 14px;
}
.top {
  background-color: rgb(255, 0, 0, 0%);
  width: 100%;
  height: 800px;
  overflow: auto;
}
.loopBody {
  display: flex;
  flex-wrap: wrap;
  padding-bottom: 30%;
  box-sizing: border-box;
  justify-content: space-between;
  .clickBody {
    overflow: hidden;
    border-radius: 7px;
    margin-top: 10px;
    box-sizing: border-box;
    width: 45%;
    overflow: hidden;
    height: 60px;
    border: 1px solid #409eff;
    position: relative;
    background-color: #66b1ff;
  }
  .body {
    margin-top: 10px;
    overflow: hidden;
    border-radius: 7px;
    box-sizing: border-box;
    width: 45%;
    overflow: hidden;
    height: 60px;
    border: 1px solid rgb(116, 116, 116);
    position: relative;
    &:hover {
      background-color: #66b1ff;
    }
  }
  .sexs {
    border-radius: 50%;
    overflow: hidden;
    position: absolute;
    width: 30%;
    top: 50%;
    transform: translate(10%, -50%);
    img {
      width: 100%;
      height: 100%;
      object-fit: contain;
    }
  }
  .texts {
    position: absolute;
    top: 50%;
    font-size: 12px;
    transform: translate(50%, -50%);
    display: block;
    width: 70%;
    text-align: center;
    color: #fff;
  }
}
</style>